package com.itluma.myshopping.dao.impl;


import com.itluma.myshopping.dao.OrderDao;
import com.itluma.myshopping.entity.Order;

import com.itluma.myshopping.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderDaoImpl implements OrderDao {
    private QueryRunner qr = new QueryRunner(JdbcUtils.getDataSource());


    private Map<String, String> map = new HashMap<>();

    {
        //   map.put("p_id", "pid");
        //  map.put("t_id", "tid");
        map.put("p_name", "productName");
        map.put("c_count", "productPrice");
        map.put("c_num", "productNumber");
        //   map.put("p_state", "pstate");
        //   map.put("p_info", "pinfo");
        //  map.put("p_price", "pprice");
    }


    @Override
    public List<Order> findById(Integer userId) throws SQLException {

        String sql = " select p.p_name , c.c_count, c.c_num from   cart as c   join  product  as p on   c.p_id=p.p_id where u_id=?";

        List<Order> order = new ArrayList<>();

            order = qr.query(sql,new BeanListHandler<Order>(Order.class),userId);

        return order;
    }

    public static void main(String[] args) throws SQLException {
      Order order =new Order();
      order.setC_num(5);
      order.setC_count(5);
 System.out.println(order.getProductTotalPrivace());


    }
}